package com.songcha.module_main.ui.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.songcha.library_business.proxy.userinfo.UserInfoManager
import com.songcha.library_common.ui.dialog.CustomDialog
import com.songcha.library_common.ui.view.CustomButton
import com.songcha.library_common.ui.view.CustomEditText
import com.songcha.library_common.util.ScreenUtil
import com.songcha.library_common.util.ToastUtil
import com.songcha.library_common.util.dp2px
import com.songcha.module_main.R
import okio.blackholeSink

class FeedbackDialog(context: Context,val block:(String)->Unit):CustomDialog(context) {

    init {
        setDialogTitle("")
        setDialogMsg("")
        setShowBtn(false)
        setWidth(ScreenUtil.getScreenWidth())
        setHeight(372.dp2px())
        setGravity(Gravity.BOTTOM)
        setRadius(floatArrayOf(10f.dp2px(),10f.dp2px(),0f,0f))
        setAnim(com.songcha.library_common.R.style.dialogBottomSlideWindowAnim)
    }

    override fun hasView(): Boolean {
        return true
    }

    override fun getView(root: ViewGroup): View? {
        val view = LayoutInflater.from(context).inflate(R.layout.main_dialog_feedback,root,false)
        val edt = view.findViewById<CustomEditText>(R.id.main_edt_feedback)
        val btn = view.findViewById<CustomButton>(R.id.main_btn_feedback)
        btn.setOnClickListener{v->
            //if(!UserInfoManager.checkJumpLogin()) return@setOnClickListener

            val content = edt.text.toString()
            if(content.isBlank()){
                ToastUtil.show("请输入意见")
                return@setOnClickListener
            }
            if(content.length > 200){
                ToastUtil.show("意见反馈不能超过200个字符")
                return@setOnClickListener
            }
            block(content)
            dismiss()
        }

        val ivClose = view.findViewById<ImageView>(R.id.main_dialog_iv_close)
        ivClose.setOnClickListener {
            dismiss()
        }

        return view
    }


}